-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retry GitHub download failures #3729
Conversation
Does this even look in the ballpark? My Python is not good 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooray!! Glad we're reusing + extending the existing decorator. The code looks pretty good to me, but I should not be the arbiter :)
Also interested to hear folks' thoughts about how best to test - perhaps mocking a package with a nonexistent tarball URL? I know test_registry_get_request_exception
added some unneeded baggage to our unit testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python checks out. However, on a personal note, I find this wrapping pattern to be particularly opaque.
Here is an example of how I might suggest refactoring this:
# no juggling of indexes which is extremely error prone
def _exception_retry(lambda_fn, retries):
if retries <= 0:
raise RegistryException('Unable to connect to registry hub')
else:
try:
return lambda_fn()
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
time.sleep(1)
_exception_retry(lambda_fn, retries - 1)
# example call:
# accepting a lambda function as a parameter allows the outer
# function to run it regardless of what parameters it takes
_exception_retry(lambda: 1+2, 5)
(the original exception is lost here, but that can be put back. I didn't write that part because it obfuscated the point I'm trying to make in the review)
In both ways of writing this, I would suggest the following tests:
- pass a function that always throws these exceptions and check that you get the right exception back
- pass a function that throws twice then returns correctly and check that you get the correct response
Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com>
* Retry GitHub download failures * Refactor and add tests * Fixed linting and added comment * Fixing unit test assertRaises Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Fixing casing Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Changing to use partial for function calls Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com>
* Retry GitHub download failures * Refactor and add tests * Fixed linting and added comment * Fixing unit test assertRaises Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Fixing casing Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Changing to use partial for function calls Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com>
* Retry GitHub download failures * Refactor and add tests * Fixed linting and added comment * Fixing unit test assertRaises Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Fixing casing Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Changing to use partial for function calls Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com>
* Retry GitHub download failures * Refactor and add tests * Fixed linting and added comment * Fixing unit test assertRaises Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Fixing casing Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Changing to use partial for function calls Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com>
* Retry GitHub download failures * Refactor and add tests * Fixed linting and added comment * Fixing unit test assertRaises Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Fixing casing Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> * Changing to use partial for function calls Co-authored-by: Kyle Wigley <kyle@fishtownanalytics.com> automatic commit by git-black, original commits: 09ea989
resolves #3546
Description
We are seeing
dbt deps
fail intermittently when trying to reach out to GitHub. We do retry logic for when we reach out to the registry hub so we want to try the same retry logic for GitHub to see if it improves the success rate ofdbt deps
.Checklist
CHANGELOG.md
and added information about my change to the "dbt next" section.